package com.top75;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/14 20:25
 */
public class Code1657 {
    public boolean closeStrings(String word1, String word2) {
        int[] char1 = new int[256];
        int[] char2 = new int[256];
        char[] chars = word1.toCharArray();
        char[] chars1 = word2.toCharArray();
        for (char c : chars) {
            char1[c]++;
        }
        for (char c : chars1) {
            char2[c]++;
        }

        for(int i = 0;i<char1.length;i++){
            if(char1[i]>0 && char2[i]==0){
                return false;
            }
            if(char1[i] == 0 && char2[i]!=0){
                return false;
            }
        }
        Arrays.sort(char1);
        Arrays.sort(char2);
        for (int i = 0; i < char1.length; i++) {
            if (char1[i] != char2[i]) {
                return false;
            }
        }
        return true;
    }
}
